Page({
  data: {
    pageTitle: '用户列表',
    pageType: '',
    showId: false,
    emptyText: '数据',
    users: []
  },
  
  onLoad: function(options) {
    // 根据options.type设置页面类型和标题
    const type = options.type || 'default';
    let title = '用户列表';
    let emptyText = '数据';
    let showId = false;
    
    switch(type) {
      case 'blacklist':
        title = '黑名单用户';
        emptyText = '黑名单用户';
        showId = true;
        break;
      case 'dislike':
        title = '不喜欢的用户';
        emptyText = '不喜欢的用户';
        break;
      case 'follow':
        title = '我的关注';
        emptyText = '关注';
        break;
      case 'fan':
        title = '我的粉丝';
        emptyText = '粉丝';
        break;
      case 'like':
        title = '被喜欢';
        emptyText = '被喜欢记录';
        break;
      case 'friend':
        title = '好友';
        emptyText = '好友';
        break;
    }
    
    this.setData({
      pageType: type,
      pageTitle: title,
      emptyText: emptyText,
      showId: showId
    });
    
    // 加载用户列表
    this.loadUserList(type);
  },
  
  // 加载用户列表
  loadUserList: function(type) {
    // 这里应该根据type调用不同的接口或从缓存中获取数据
    // 这里使用模拟数据
    let users = [];
    
    // 根据不同类型生成不同的模拟数据
    if (type === 'blacklist') {
      users = [
        {
          id: 'user001',
          nickName: '黑名单用户1',
          avatarUrl: 'https://objectstorageapi.bja.sealos.run/a0qepsyj-001/text/profile/default-avatar.jpg',
          school: '某大学',
          isFollowing: false
        },
        {
          id: 'user002',
          nickName: '黑名单用户2',
          avatarUrl: 'https://objectstorageapi.bja.sealos.run/a0qepsyj-001/text/profile/default-avatar.jpg',
          school: '某学院',
          isFollowing: false
        }
      ];
    } else if (type === 'dislike') {
      users = [
        {
          id: 'user003',
          nickName: '不喜欢的用户1',
          avatarUrl: 'https://objectstorageapi.bja.sealos.run/a0qepsyj-001/text/profile/default-avatar.jpg',
          school: '某大学',
          isFollowing: false
        },
        {
          id: 'user004',
          nickName: '不喜欢的用户2',
          avatarUrl: 'https://objectstorageapi.bja.sealos.run/a0qepsyj-001/text/profile/default-avatar.jpg',
          school: '某学院',
          isFollowing: true
        }
      ];
    } else if (type === 'follow') {
      users = [
        {
          id: 'user005',
          nickName: '关注用户1',
          avatarUrl: 'https://objectstorageapi.bja.sealos.run/a0qepsyj-001/text/profile/default-avatar.jpg',
          school: '某大学',
          title: '学霸',
          isFollowing: true
        },
        {
          id: 'user006',
          nickName: '关注用户2',
          avatarUrl: 'https://objectstorageapi.bja.sealos.run/a0qepsyj-001/text/profile/default-avatar.jpg',
          school: '某学院',
          isFollowing: true
        }
      ];
    } else if (type === 'fan') {
      users = [
        {
          id: 'user007',
          nickName: '粉丝1',
          avatarUrl: 'https://objectstorageapi.bja.sealos.run/a0qepsyj-001/text/profile/default-avatar.jpg',
          school: '某大学',
          isFollowing: false
        },
        {
          id: 'user008',
          nickName: '粉丝2',
          avatarUrl: 'https://objectstorageapi.bja.sealos.run/a0qepsyj-001/text/profile/default-avatar.jpg',
          school: '某学院',
          isFollowing: true
        }
      ];
    } else if (type === 'like') {
      users = [
        {
          id: 'user009',
          nickName: '点赞用户1',
          avatarUrl: 'https://objectstorageapi.bja.sealos.run/a0qepsyj-001/text/profile/default-avatar.jpg',
          school: '某大学',
          time: '2023-03-25 14:30',
          isFollowing: false
        },
        {
          id: 'user010',
          nickName: '点赞用户2',
          avatarUrl: 'https://objectstorageapi.bja.sealos.run/a0qepsyj-001/text/profile/default-avatar.jpg',
          school: '某学院',
          time: '2023-03-24 09:15',
          isFollowing: true
        }
      ];
    } else if (type === 'friend') {
      users = [
        {
          id: 'user011',
          nickName: '好友1',
          avatarUrl: 'https://objectstorageapi.bja.sealos.run/a0qepsyj-001/text/profile/default-avatar.jpg',
          school: '某大学',
          title: '技术达人',
          isFollowing: true
        },
        {
          id: 'user012',
          nickName: '好友2',
          avatarUrl: 'https://objectstorageapi.bja.sealos.run/a0qepsyj-001/text/profile/default-avatar.jpg',
          school: '某学院',
          isFollowing: true
        }
      ];
    }
    
    this.setData({ users });
  },
  
  // 返回上一页
  navigateBack: function() {
    wx.navigateBack();
  },
  
  // 点击用户
  onUserTap: function(e) {
    const userId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/user-profile/user-profile?id=${userId}`
    });
  },
  
  // 解除黑名单
  unblockUser: function(e) {
    const userId = e.currentTarget.dataset.id;
    wx.showModal({
      title: '解除黑名单',
      content: '确定将该用户从黑名单中移除吗？',
      success: (res) => {
        if (res.confirm) {
          // 移除黑名单用户（实际应调用接口）
          const users = this.data.users.filter(user => user.id !== userId);
          this.setData({ users });
          
          wx.showToast({
            title: '已解除黑名单',
            icon: 'success'
          });
        }
      }
    });
  },
  
  // 移除不喜欢的用户
  undislikeUser: function(e) {
    const userId = e.currentTarget.dataset.id;
    wx.showModal({
      title: '移除不喜欢',
      content: '确定将该用户从不喜欢列表中移除吗？',
      success: (res) => {
        if (res.confirm) {
          // 移除不喜欢的用户（实际应调用接口）
          const users = this.data.users.filter(user => user.id !== userId);
          this.setData({ users });
          
          wx.showToast({
            title: '已移除',
            icon: 'success'
          });
        }
      }
    });
  },
  
  // 切换关注状态
  toggleFollow: function(e) {
    const userId = e.currentTarget.dataset.id;
    const users = this.data.users.map(user => {
      if (user.id === userId) {
        return {
          ...user,
          isFollowing: !user.isFollowing
        };
      }
      return user;
    });
    
    this.setData({ users });
    
    // 提示信息
    const followingUser = users.find(user => user.id === userId);
    wx.showToast({
      title: followingUser.isFollowing ? '已关注' : '已取消关注',
      icon: 'success'
    });
  },
  
  // 发送私信
  sendMessage: function(e) {
    const userId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/chat/chat?userId=${userId}`
    });
  }
}); 